<?php
/**
 * Created by Shijie Liu. 2017/6/19
 * 查询购物车信息
 */

    /**
     * @param $user_id
     * @return mixed|string  返回购物车信息数组，或状态码
     */
    function getShopInfo()
    {
        $user_id = $_COOKIE["user_login"];
        if (isset($user_id)){

            $sql_c = "SELECT book.book_id,book.book_name,book.book_author,book_cart.num,book.book_price,
    book.book_price*book_cart.num as sum from book,book_cart,user 
    where book_cart.book_id = book.book_id AND user.user_id = book_cart.user_id AND user.user_id= $user_id;";
            $result = queryDB($sql_c);

        }else{
            $result = "unregistered";  //未注册
        }
        return $result;
    }

    /**
     * @param $sql
     * @return bool|mysqli_result
     */
    function queryDB($sql){

        $con_db = mysqli_connect("localhost","root","19971010","book_store");

        if (empty($con_db)){
            die("数据库连接错误!".mysqli_error($con_db));
        }else{
            $result = mysqli_query($con_db,$sql);
        }
        $con_db->close();
        return $result;
    }